package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void insertBatch(List<OrderDetail> orderDetails);

    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    void update(Orders orders);

    @Select("select id from orders where status = #{pendingPayment} and order_time < #{time};")
    List<Long> getIdsByTime(LocalDateTime time, Integer pendingPayment);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> getByOrderIdForDetail(Long id);

    Page<Orders> getByUserIdForOrders(Long userId, Integer status);

    Page<Orders> getAllOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select concat(name, '[', ifnull(dish_flavor, '原味'), ']') as t from order_detail where order_id = #{id}")
    List<String> getDishesString(Long id);

    OrderStatisticsVO getStatistics();

    Integer getOrdersCount(Map<String, Object> map);
}
